//主分支
#ifndef _MACHINE_STAT_H
#define _MACHINE_STAT_H

#include "sc95f.h"
#include "key_process.h"
#include "soft_time.h"
typedef  struct {
	uint8_t sec;
	uint8_t min;
	uint8_t hour;
	uint8_t day;
	uint8_t mouth;
	uint8_t year;  
}DATE_STAT;
extern DATE_STAT date_stat;
extern uint8_t dis_remember;

#define TIME_READ                 1
#define RESERVATION_DATA          3

#define DEF_PLAIN_TEMP        450
#define DEF_KITCHEN_TEMP      350
#define DEF_SHOWER_TEMP       420


typedef struct
{
	uint8_t furnace_re_switch;
	uint8_t cycle_re_switch;
	uint8_t chang_open_cycle;
	uint8_t furnace_re_time[RESERVATION_DATA];
	uint8_t cycle_re_time[RESERVATION_DATA];
}WIFI_RESERVATION;

typedef struct 
{
	uint8_t poweron;
	uint8_t furnace_mode;
	uint8_t furnace_off;
	uint8_t heat_water_temp;
	uint8_t heat_furnace_temp;
	uint8_t cycle_on;
	uint8_t cycle_mode;
	uint8_t reset_sw;
	//uint8_t shiyunxing;
	uint8_t quick_furnace_mode;
	uint8_t heat_water_temp_min;
	uint8_t heat_water_temp_max;
	uint8_t heat_furnace_temp_max;
	uint8_t furnace_prevent;
	//uint8_t shuiya_display;
}HEAT_FURNACE_F4_TXTE;

typedef struct 
{
	uint8_t water_temp;//1
	uint8_t err_code_hight;//3
	uint8_t err_code_low;
	uint8_t err_tyde;//5
	uint8_t fire_tyde;
	uint8_t run_mode;//7
	uint8_t mode_set;
	uint8_t try_runmode;//9
	uint8_t water_temp_max;//10
	uint8_t water_temp_min;//12
	uint8_t circular_mode;
	uint8_t circular_mode_set;//15
	uint8_t quick_furnace_set;
	uint8_t prevent_frostbite;//17
	uint8_t hydraulic_sensors;
	uint8_t heat_furnace_temp;//19
	uint8_t heat_furnace_temp_max;//21
	uint8_t heat_furnace_temp_min;//23
	uint8_t furnace_prevent_set;

}HEAT_FURNACE_F1_TXTE;

typedef struct 
{
	// uint8_t Gas_species:2;
	// uint8_t Liters:3;
	// uint8_t Min_60_timer:1;
	// uint8_t Solar_energy:1;
	// uint8_t Highland:2;
	// uint8_t Exhaust:1;
	// uint8_t Reserved:6;
	uint8_t Gas_species:1;
	uint8_t Liters:2;
	uint8_t Highland:3;
	uint8_t furnace_min_temp_change:1;
	uint8_t Reserved:1;

	uint8_t furnace_change:1;
	uint8_t Pump_water_volume_switching:1;
	uint8_t Reserved1:6;

	uint8_t proportion_max;
	uint8_t proportion_min;

	uint8_t fire_max_and_min;
	uint8_t length_change;
	uint8_t furnace_stabilize;
	uint8_t pump_run_time;
	uint8_t furnace_temp_chaju_radiator;
	uint8_t furnace_temp_chaju_floor;
	uint8_t Wait_time_for_heating_reboot;
	uint8_t heat_water_to_heat_furnace_wait_time;
	uint8_t energy_save_frie_run_time;
	uint8_t go_out_frie_run_time;

	uint8_t temp_control_stop_temp;
	uint8_t room_temp_control_stop_temp;
	uint8_t hot_water_start_work_value;
	uint8_t hot_water_start_work_stop_temp;

}HEAT_FURNACE_F0_TXTE;
/*
typedef enum{
	OFFLINE,
	ONLINE,//1
}NET_Stat ;

typedef enum{
    SMARTLINK_FAILED ,
    SMARTLINK_SUCCESS,//1
}SMARTLINK_Stat;

typedef enum{
    NO_SIGNAL,	
    LOW,
    MID,
    HIGH,
}SIGNAL_Stat;

typedef struct{
	NET_Stat       net_stat;
	SMARTLINK_Stat smart_link_stat;
	SIGNAL_Stat    signal;
}WIFI_Stat;
*/
#define OPEN_POWER_FLAG
#define STA_0      0
#define STA_1      1
#define STA_2      2
#define STA_3      3
#define STA_4      4
#define STA_5      5

#define STA_FIRE_0  0
#define STA_FIRE_1  1

#define DECREASE_TEMP_5   5
#define INCREASE_TEMP_5   5

#define DECREASE_TEMP_10   10
#define INCREASE_TEMP_10   10

#define TEMP_INCREASE      475
#define TEMP_DECREASE      355

#define TEMP_INCREASE_1      480
#define TEMP_DECREASE_1      350

#define TEMP_320             320

#define TEMP_CHANGE        480

#define RUN_PLAIN          0X00
#define RUN_KITCHEN        0X01
#define RUN_SHOWER         0X02
//#define RUN_COOL_HOT       0X03

#define LONG_KEY_TIME      50

#define CYCLE_TIMES        62
//#define Rinnai_version 35    //每�?�修改过后，版本加一，�?�数来源根据林内�?件更新明�?.xls�?，跟新�?�数

/*
 	DIGITAL_CODE_A,  //0
    DIGITAL_CODE_b,  //1
    DIGITAL_CODE_C,  //2
    DIGITAL_CODE_d,  //3
    DIGITAL_CODE_E,  //4
    DIGITAL_CODE_F,  //5
    DIGITAL_CODE_g,  //6
    DIGITAL_CODE_H,  //7
    DIGITAL_CODE_S,  //8
    DIGITAL_CODE_P,  //9 
    DIGITAL_CODE_L,  //10
    DIGITAL_CODE_n,  //11
    DIGITAL_CODE_T,  //12
    DIGITAL_CODE_K,  //13
    DIGITAL_CODE_g   //14
*/
#define Rinnai_number_version 1   
#define Rinnai_letter_version 0

typedef enum{

    MODE_INIT,//0
#ifdef OPEN_POWER_FLAG
    MODE_OPEN_POWER,//1
#endif
    MODE_POWEROFF,//2
    MODE_RUN,
    MODE_ERR,
    MODE_FACTORY_TEST,
    MODE_COMM_ERR,
	MODE_WIFI,//���ù�
	MODE_VERSION,//�汾��ʾ
	
	MODE_IN_OPEN_POWER,
	MODE_OUT_OPEN_POWER,
    
    MODE_FACTORY,
	MODE_TEST = 0XFF,
    
}Machine_Stat ;

extern Machine_Stat MachineStat;
typedef enum{
    SC_ALL_CLOSE,
    SC_SUPER_OPEN,
    SC_CYCLE_OPEN,
}SuperCycle_t;

typedef struct{
	uint16_t  Send_SetHeatTemp;
	//uint8_t Sendtemp_old;
	uint8_t Sendtemp_h;
	uint8_t Sendtemp_l;
	uint16_t  SetHeatTemp;
	//uint8_t temp_old;
	uint8_t temp_h;
	uint8_t temp_l;
	uint8_t  err_code_h;
	uint8_t  err_code_l;
	uint8_t  err_code_l_h;
	uint8_t  err_code_l_l;
	uint8_t  err_type;
	uint8_t  fire_stat; //
	uint8_t  power_stat; //30-31
	uint8_t  eco_stat;
	uint8_t  eco_mode;
	uint16_t  SetHeatTempMax;
	uint16_t  SetHeatTempMin;
	//add
	uint8_t  akey_cycle;
	uint8_t  cycle_mode;
//	uint8_t  cycle_book;
	uint8_t  super_mode;
	uint8_t  cold_stat;
	uint8_t  running_mode;
	uint8_t  bathtub_mode;       /* 浴缸状态编号 */
	uint8_t  BathtubSetWater;    /* 设定水量 */
	uint8_t  BathtubRemainWater; /* 浴缸剩余水量 */
	//uint8_t  send_eco_mode;
	uint8_t  send_akey_cycle;
	uint8_t  send_cycle_mode;
//	uint8_t  send_cycle_book;
    uint8_t  send_super_mode;
	uint8_t  send_cold_stat;
	uint8_t  send_running_mode;
	uint8_t  cool_and_hot; 
	//uint8_t  fluctuation_mode; 
    SuperCycle_t  SuperCycle;  /* 0: all close, 1: super open, 2: cycle open */
}HEATER_INFO;
#define CYCLE_LEN   3
typedef struct 
{
	uint8_t OrderEnable;
	uint8_t cycle_times[CYCLE_LEN];
    
}CYCLE_SWITCH;

typedef enum{
    ORDER_STA_INVALID,
	ORDER_STA_RUN,
	ORDER_STA_PAUSE,
}OrderState_t;

typedef struct{
	uint8_t      Enable;
	uint8_t      bPause;
	OrderState_t State; 
	uint8_t      TimeTable[3];
}CycleOrder_t;

extern uint8_t CycleActiveSrc;
enum{
	CYCLE_SRC_KEY, /* 手动触发循环 */
	CYCLE_SRC_ORDER, /* 预约触发 */
};
// typedef struct 
// {
// 	uint8_t times_flag;
// 	uint8_t times_hour;
// 	uint8_t times_min;
// 	uint8_t times_s;
// }TIMES_STRUCT;
typedef struct 
{
	uint8_t time_stat1;
	uint8_t day_sec;
	uint8_t day_min;
	uint8_t day_hour;
}TIME_STAT;

extern uint16_t  three_time;
extern uint8_t  three_3_flg;
extern HEATER_INFO heater_info;
extern Time wifitime;
extern uint8_t smartlink_start;
extern TIME_STAT time_stat;
extern CYCLE_SWITCH cycle_switch;
extern Time flash_time;

extern CycleOrder_t CycleOrder;
extern uint16_t CycleDuration;
extern uint16_t mode_save_temp[];
void machine_init(void);
void machine_stat(void);
void reservation_function(void);	

extern Time cycle_time;
void SetRunMode(uint8_t run_mode);
void CycleTask(void);
uint8_t IsLock(void);
uint8_t IsSelfCheckMode(void);
uint8_t IsBathtubeFinish(void);
void EnterFactoryMode(uint8_t fact);
uint8_t IsFactoryMode(void);
#endif